<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:100%;" id="dataFrm">
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">用户名:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input lname" name="lname" lay-verify="required" placeholder="请输入用户名">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input lpass" name="lpass" lay-verify="required" placeholder="请输入密码">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">真实姓名:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input rname" name="rname" lay-verify="required" placeholder="请输入真实姓名">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">年龄:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input age" name="age" lay-verify="required" placeholder="请输入年龄">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block gender">
            <input type="radio" name="gender" value="M" title="男" checked>
            <input type="radio" name="gender" value="F" title="女">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">地址:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input address" name="address" lay-verify="required" placeholder="请输入地址">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input phone" name="phone" lay-verify="required" placeholder="请输入手机号">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">部门:</label>
        <div class="layui-input-block">
            <select id="userDept" name="dept.id" class="userGrade" lay-filter="userDept">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">职位:</label>
        <div class="layui-input-block">
            <select id="userPost" name="post.id" class="userGrade" lay-filter="userPost">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">生日:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input birthday" name="birthday" lay-verify="required" placeholder="请输入生日">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">身份证:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input card" name="card" lay-verify="required" placeholder="请输入身份证号">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">入职时间:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input entryTime" name="entryTime" lay-verify="required" placeholder="请输入入职时间">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block isDisable">
            <input type="radio" name="isDisable" value="1" title="启用" checked>
            <input type="radio" name="isDisable" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addUser">立即添加</button>
            <button id="esc" type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="resources/layui/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl','upload'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
            upload=layui.upload;

            //生日框的时间插件绑定
            laydate.render({
             elem: ".birthday" //指定元素
             });

            //入职时间框的时间插件绑定
            laydate.render({
                elem:".entryTime"
            });

        //取消
        $("#esc").click(function () {
            var index1=parent.layer.getFrameIndex(window.name)
            parent.layer.close(index1);
        });

        //请求获取数据
        //动态绑定下拉菜单的数据
        var html_dept;
        $.ajax({
            url:'/dictionarys/deptList.do',
            success:function (data) {
                html_dept += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    html_dept += ("<option value='" + data[i].id + "'>" + data[i].name + "</option>")
                }
                $("#userDept").append(html_dept);
                form.render('select');
            }
        });
        var html_post;
        $.ajax({
            url:'/dictionarys/postList.do',
            success:function (data) {
                html_post += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    html_post += ("<option value='" + data[i].id + "'>" + data[i].name + "</option>")
                }
                $("#userPost").append(html_post);
                form.render('select');
            }
        });

        form.on("submit(addUser)",function (data) {
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            //实际使用时的提交数据
            var params=$("#dataFrm").serialize();
            // console.log(params);
            $.post("users.do",params,function (res) {
                console.log(res.code);
                if(res.code==4004){
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    var index1=parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index1);
                    parent.location.reload();
                }else if(res.code=-4003){
                    layer.msg(res.msg);
                }else if(res.code=-4004){
                    layer.msg(res.msg);
                }
            },"json");
            return false;
        });
    })
 </script>
</body>
</html>